import { Body, ClassSerializerInterceptor, Controller, Get, HttpException, Post, UseGuards, UseInterceptors } from '@nestjs/common';
import { AuthService } from './auth.service';
import { SigninUserDto } from './dto/signin-user.dto';
import { Public } from '../decorators/public.decorator';
// import { SerializeInterceptor } from 'src/interceptors/serialize.interceptor';

@Controller('auth')
@UseInterceptors(ClassSerializerInterceptor)
export class AuthController {
  constructor(
    private readonly authService: AuthService,
  ) {}

  @Public()
  @Get()
  getHello(): string{
    return 'Hello World!'
  }
  @Public()
  @Post('/signin')
  // 登录
  signin(@Body() dto: SigninUserDto){
    const { username, password } = dto;
    return this.authService.signin(username, password);
  }

  @Public()
  @Post('/signup')
  // @UseInterceptors(SerializeInterceptor)
  // 注册
  signup(@Body() dto: SigninUserDto){
    const { username, password } = dto;
    // if (!username ||!password) {
    //   throw new HttpException('用户名或密码不能为空', 400);
    // }
    // // 正则校验用户名密码合法性
    // if (typeof username!=='string' || typeof password!=='string'){
    //   throw new HttpException('用户名或密码必须为字符串', 400);
    // }
    // if (username.length < 6 || password.length < 6){
    //   throw new HttpException('用户名和密码长度必须大于等于6', 400);
    // }
    return this.authService.signup(username, password);
  }
}
